#ifndef OBJECTMANAGER_H
#define OBJECTMANAGER_H

#include <QObject>
#include <QList>
#include <QPair>
#include <QPoint>
#include <SFML/Graphics.hpp>
#include "yamlstream.h"

class ObjectManager : public QObject
{
    Q_OBJECT
public:
    struct Shape
    {
      Shape()
      {
          type     = "box";
          density  = 0;
          friction = 0;
          angle    = 0;
          sensor   = false;
      }

       QString             name;
       QString             type;
       float               density, friction, angle;
       sf::Vector2f        size;
       sf::Vector2f        position;
       QList<sf::Vector2f> vertices;
       bool                sensor;
       QString             collisionGroup;
    };

    struct Object
    {
      Object()
      {
        type             = "dynamic";
        isBullet         = false;
        hasFixedRotation = false;
      }

      QString                 name;
      QString                 type;
      bool                    isBullet;
      bool                    hasFixedRotation;
      QList<Shape>            fixtures;
      QList<QString>          textures;
      QList<QString>          animations;
    };

    explicit ObjectManager(QObject *parent = 0);

    Object*               GetObject(const QString& name);
    void                  AddObject(Object);
    void                  DelObject(const QString& name);
    void                  SaveObject(const Object);
    const QList<Object>&  Objects(void) { return (_objects); }

    void                  Load(const QString&);
    void                  Save(const QString&);
    void                  Clear(void) { _objects.clear(); }

signals:
    void                  Updated(void);
    
public slots:
    
private:
    QList<Object>         _objects;

    static void           SaveGraphics(YamlStream&, const QString&, const QList<QString>&);
    static void           SaveShapeBox(YamlStream&, const Shape&);
    static void           SaveShapeCircle(YamlStream&, const Shape&);
    static void           SaveShapePolygon(YamlStream&, const Shape&);

    struct funcSaveShape
    {
        const QString key;
        void          (*function)(YamlStream&, const Shape&);
    };

    static funcSaveShape  _funcsShapeSave[];
};

#endif // OBJECTMANAGER_H
